export const getTimeYearStr = (time, type = 'date', reg=['年', '月', '日', '时', '分', '秒']) => {
	let temptime = time ? parseInt(time, 10) : null
	let result = '---'
	if (temptime) {
		let tdate = new Date(temptime * 1000)
		let year = tdate.getFullYear()
		let month = (tdate.getMonth() + 1) > 9 ? (tdate.getMonth() + 1) : '0' + (tdate.getMonth() + 1)
		let date = (tdate.getDate()) > 9 ? (tdate.getDate()) : '0' + (tdate.getDate())
		if (type == 'date' || type == 'time') { 
			result = `${year}${reg[0]}${month}${reg[1]}${date}${reg[2]}`
		}
		if(type == 'time') {
			let hour = (tdate.getHours()) > 9 ? (tdate.getHours()) : '0' + (tdate.getHours())
			let minute = (tdate.getMinutes()) > 9 ? (tdate.getMinutes()) : '0' + (tdate.getMinutes())
			let second = (tdate.getSeconds()) > 9 ? (tdate.getSeconds())  : '0' + (tdate.getSeconds())
			result += `${hour}${reg[3]}${minute}${reg[4]}${second}${reg[5]}`
		}
	}
	return result
}


// /*
//  * @Author: 阿牛
//  * @Date:  25.5.6
//  * @desc  url参数转对象
//  * @params params -> 传入数据 String | Object
//  * @params  _needEncode -> 是否需要编码 默认 true
//  */
// export const urltoobj = (_params = '', _needEncode = true) => {
// 	const isUrlStr = !(_params instanceof Object);
// 	isUrlStr && _params.includes('?') && (_params = _params.split('?')[1]);
// 	const paramsVM = new URLSearchParams(_params);
// 	!_needEncode && paramsVM.forEach((v, k) => paramsVM.set(k, decodeURIComponent(v)));
// 	if (isUrlStr) return Object.fromEntries(paramsVM);
// 	return _needEncode ? String(paramsVM) : decodeURIComponent(paramsVM);
// }




// /*
//  * @Author: 阿牛
//  * @Date:  25.5.6
//  * @desc  url参数转对象
//  * @params params -> 传入数据 String | Object
//  * @params  _needEncode -> 是否需要编码 默认 true
//  */
export const urlToObj = (url) => {
  const obj = {};
  
  // 处理查询参数部分
  const queryIndex = url.indexOf('?');
  if (queryIndex !== -1) {
    const queryStr = url.slice(queryIndex + 1);
    const pairs = queryStr.split('&');
    
    pairs.forEach(pair => {
      const [key, value] = pair.split('=');
      if (key) {
        // 解码 URL 编码的字符
        const decodedKey = decodeURIComponent(key);
        const decodedValue = value ? decodeURIComponent(value) : '';
        
        // 处理重复键的情况（转换为数组）
        if (obj.hasOwnProperty(decodedKey)) {
          if (Array.isArray(obj[decodedKey])) {
            obj[decodedKey].push(decodedValue);
          } else {
            obj[decodedKey] = [obj[decodedKey], decodedValue];
          }
        } else {
          obj[decodedKey] = decodedValue;
        }
      }
    });
  }
  
  return obj;
}
